﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Login.Tools;
using MySql.Data.MySqlClient;
namespace Login.view
{
    public partial class UserSelect : UserControl
    {
        GroupBox b1;
        JDBCTool jb;
        public UserSelect()
        {
            InitializeComponent();
        }
        public UserSelect(GroupBox temp)
        {
            b1 = temp;
            InitializeComponent();
        }

        private void UserSelect_Load(object sender, EventArgs e)
        {
            jb = new JDBCTool();
            String sql = "select * from info";
            MySqlConnection con = jb.getmysqlcon();
            MySqlCommand cmd = con.CreateCommand();
            cmd.CommandText = sql;
            MySqlDataAdapter adpt = new MySqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            adpt.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            b1.Controls.Clear();
            b1.Controls.Add(new UserMain(b1));
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != null)
            {
                String sql = "select * from info where uid = " + textBox1.Text ;
                MySqlConnection con = jb.getmysqlcon();
                MySqlCommand cmd = con.CreateCommand();
                cmd.CommandText = sql;
                MySqlDataAdapter adpt = new MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                if (adpt == null)
                {
                    dataGridView1.DataSource = null;
                    return;
                }
                adpt.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0].DefaultView;
            }
        }

       
    }
}
